package com.zhangxu.microservice.system.web.controller.noRight;

import com.zhangxu.microservice.common.result.CommonResult;
import com.zhangxu.microservice.system.biz.dto.TokenRespDTO;
import com.zhangxu.microservice.system.biz.service.AuthService;
import com.zhangxu.microservice.system.web.convert.AuthConverter;
import com.zhangxu.microservice.system.web.request.LoginReq;
import com.zhangxu.microservice.system.web.response.TokenResp;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("noRight")
@RequiredArgsConstructor
@Tag(name = "登录接口(不鉴权)")
public class AuthController {

    private final AuthService authService;
    private final AuthConverter authConverter;

    @PostMapping("/login")
    public CommonResult<TokenResp> login(@Validated @RequestBody LoginReq request) {
        TokenRespDTO tokenRespDTO = authService.login(authConverter.toLoginReqDTO(request));
        return CommonResult.success(authConverter.toTokenResp(tokenRespDTO));
    }

}